package com.rency.ues.webapp.listener;

import com.rency.ues.webapp.common.Constants;
import com.rency.ues.webapp.common.WebProperty;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;

public class ServletContextInitListener implements ApplicationContextAware {
	
	private WebProperty webProperty;

	public void setWebResource(WebProperty webProperty) {
		this.webProperty = webProperty;
	}

	@Override
	public void setApplicationContext(ApplicationContext ctx)throws BeansException {
		WebApplicationContext wc = (WebApplicationContext) ctx;
		ServletContext sc = (ServletContext) wc.getBean(WebApplicationContext.SERVLET_CONTEXT_BEAN_NAME);
		sc.setAttribute(Constants.SYS_WEB_RESOURCE_KEY, webProperty);
	}
	
	public WebProperty getWebProperty() {
		return webProperty;
	}

	public void setWebProperty(WebProperty webProperty) {
		this.webProperty = webProperty;
	}

}
